This is a test nodeJs app.
Syntax: docker build -t <image_name>:<tag> -f <Dockerfile_name> <build_context>
docker build -t node:1 -f dockerfile.nodejs .
Flag Details:
-t node:1 → Name the image node with tag 1. → Build context is the current directory (where Dockerfile is located).Advance docker build cmd;
docker build -t <image_name>:<tag> -f <Dockerfile_name> <build_context_dir>docker build -t myapp:latest -f dockerfile.nodejs .Syntax: docker run -id --name <container_name> -p <host_port>:<container_port> <image_name>:<tag>
Example:
docker run -id --name node -p 3001:3000 node:1
Flag Details:
Syntax: docker images
Example:
docker images
Syntax: docker ps
Example:
docker ps
Syntax: docker ps -a
Example:
docker ps -a
Syntax: docker stop <container_name_or_id>
Example:
docker stop node
Syntax: docker rm <container_name_or_id>
Example:
docker rm node
Syntax: docker rmi <image_name>:<tag>
Example:
docker rmi node:1
Step 1: Log in to Docker Hub
Step 2: Go to Security Settings
Step 3: Create a New Token
Syntax: echo "<your_password_or_PAT>" | docker login -u <username> --password-stdin
Example:
echo "<your_pat_password_here>" | docker login -u <your_docker_user_name> --password-stdin
Syntax:
docker tag <local_image> <username>/<repository>:<tag>
docker push <username>/<repository>:<tag>
Example:
docker tag node:1 <your_docker_user_name>/<your_repo_name>:1
docker push <your_docker_user_name>/<your_repo_name>:1
Syntax: docker pull <username>/<repository>:<tag>
Example:
docker pull <your_docker_user_name>/<your_repo_name>:1
Syntax: docker run -d --name <container_name> -v <host_path>:<container_path> <image_name>:<tag>
Example:
docker run -d --name node -v ./app/:/usr/src/app node:1
mkdir -p /opt/jenkins/jenkins_home chown -R 1000:1000 /opt/jenkins/jenkins_home
docker run -d \
--name jenkins \
-p 8080:8080 \
-p 50000:50000 \
-v /opt/jenkins/jenkins_home:/var/jenkins_home \
jenkins/jenkins:lts
Explanation:
-d → Run in detached mode (background)--name jenkins → Container name-p 8080:8080 → Exposes Jenkins web UI on host port 8080-p 50000:50000 → Exposes port for Jenkins agents (if needed)-v /opt/jenkins/jenkins_home:/var/jenkins_home → Docker volume to persist Jenkins configuration and jobsdocker run -d \
--name jenkins \
-u root \
-p 8080:8080 -p 50000:50000 \
-v /opt/jenkins/jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkins/jenkins:lts
docker exec -it jenkins bash
apt-get update && apt-get install -y docker.io
docker run -d \
--name jenkins-docker \
-u root \
-p 8080:8080 -p 50000:50000 \
-v /opt/jenkins/jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkins/jenkins:lts-jdk17
cat jenkins-run-docker.sh
#!/bin/bash
echo "Stop and remove the running container, if existing !!!"
docker rm -f jenkins 2>/dev/null || echo "No container named jenkins exists, skipping remove."
sleep 2
echo "Creating a new jenkins container with presistent volume."
docker run -d \
--name jenkins \
-u root \
-p 8080:8080 -p 50000:50000 \
-v /opt/jenkins/jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkins/jenkins:lts
#
chmod +x jenkins-run-docker.sh
./jenkins-run-docker.sh
# output:
root@SagarMalla-System:/opt/jenkins# ./jenkins-run-docker.sh
Stop and remove the running container, if existing !!!
Creating a new jenkins container with presistent volume.
affaa433f1ef5a4347d620f0a2400ba89b6fe82b88468f13804d35706600e29d
root@SagarMalla-System:/opt/jenkins#
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
docker exec -it -u root jenkins apt-get update -y
docker exec -it jenkins apt-get install -y docker.io
# docker exec -it jenkins bash -c "apt-get update -y && apt-get install -y git docker.io"
docker exec -it jenkins git -v && docker -v
#
root@SagarMalla-System:/opt/jenkins# docker exec -it jenkins git -v && docker -v
git version 2.39.5
Docker version 28.3.3, build 980b856
root@SagarMalla-System:/opt/jenkins#
| Aspect | Docker | Kubernetes |
|---|---|---|
| Role | Containerization (build & run containers) | Orchestration (manage containers at scale) |
| Scope | Single host | Multi-node cluster |
| Scaling | Manual / Docker Swarm | Automatic, built-in HPA |
| Networking | Basic container networking | Advanced service discovery & load balancing |
| Storage | Volumes | PV & PVC (dynamic storage) |
| High Availability | Limited | Built-in self-healing & HA |
| Updates | Manual | Rolling updates & rollbacks |
| Best For | Running containers locally or small scale | Managing containers in production at scale |
| Aspect | Docker | Docker Swarm | Kubernetes |
|---|---|---|---|
| Role | Containerization | Orchestration (by Docker) | Orchestration (industry standard) |
| Scope | Single host | Multi-host clusters | Multi-node clusters |
| Setup | Simple | Easy, built-in with Docker | Complex, more components |
| Scaling | Manual | Basic scaling | Advanced autoscaling |
| Networking | Basic | Simple overlay networking | Advanced networking & Ingress |
| High Availability | Limited | Basic failover | Strong HA & self-healing |
| Updates | Manual | Rolling updates | Rolling updates & rollbacks |
| Best For | Running containers locally | Small-to-medium clusters | Large-scale production |
Definition of DevOps: DevOps is a culture and set of practices that combine software development (Dev) and IT operations (Ops) to deliver applications faster, more reliably, and with continuous improvement.
Why DevOps:
Short version: DevOps = faster, reliable software through collaboration and automation.